package com.winning.pmph.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.winning.pmph.entity.ExamOutlineTag;
import com.winning.pmph.mapper.ExamOutlineTagMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

@Component
public class ExamOutlineTagService extends ServiceImpl<ExamOutlineTagMapper, ExamOutlineTag> {
    @Cacheable("exam_outline_tag")
    public ConcurrentHashMap<String, ExamOutlineTag> selectMap(Consumer<LambdaQueryWrapper<ExamOutlineTag>> consumer) {
        ConcurrentHashMap<String, ExamOutlineTag> collect = lambdaQuery()
                .nested(Objects.nonNull(consumer), consumer)
                .list()
                .stream()
                .collect(Collectors.toMap(ExamOutlineTag::getId, Function.identity(), (a, b) -> a, ConcurrentHashMap::new));
        return collect;
    }
}
